package com.cxp.serverdemo.controller;

import com.cxp.serverdemo.Repository.RoleRepository;
import com.cxp.serverdemo.bean.sys.bean.Menu;
import com.cxp.serverdemo.bean.sys.bean.Role;
import com.cxp.serverdemo.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class test {
     private Logger logger= LoggerFactory.getLogger(test.class);

     @Autowired
     RoleRepository roleRepository;
    @Autowired
    MenuService menuService;

/*    @RequestMapping(value = "/")
    public String index(){
        return "index";
    }

    @RequestMapping(value = "/login")
    public String login(){
        return "login";
    }*/

    @RequestMapping(value = "/test")
    public String test(){
        return "test";
    }

    @GetMapping(value = "/test01/{name}")
    public String test01(@PathVariable("name") String name){
        return "你好，"+ name +"先生";
    }

    //@PostMapping(value = "/test02")
    @RequestMapping(value = "/test02")
    public String test02(@RequestParam("name") String name,@RequestParam("password") String password){
        logger.info("name+password::"+name +"/"+password);
        if(name.equals("user") & password.equals("123")){
            return name + "你好，你已经注册成功";
        }
        return "对不起，注册失败";
    }

    @GetMapping(value = "/test03")
    public String test03(@RequestParam("name") String name,@RequestParam("password") String password){
        logger.info("name+password::"+name +"/"+password);
        if(name.equals("user") & password.equals("123")){
            return name + "你好，你已经注册成功";
        }
        return "对不起，注册失败";
    }

    @GetMapping(value = "/test04")
    public List<Role> test04(@RequestParam("name") String name){
        logger.info("name+password::"+name);
        List<Role> roles = roleRepository.findRolesByUsername(name);
        return roles;
    }

    @GetMapping(value = "/test05")
    public List<Menu> test05(@RequestParam("id") String id){
        logger.info("name::"+id );
        List<Menu> menus = menuService.getAllMenu();
        return menus;
    }

}
